package com.mmall.util;

/**
 * @Author 侯俊杰
 * @Date 2017/11/21
 * @Time 16:33
 **/
public class PathUtil
{
    /**
     * 通过类路径来取工程路径
     *
     * @return
     * @throws Exception
     */
    public String getAbsolutePathByClass()
    {
        String webPath = this.getClass().getResource("/").getPath().replaceAll("^\\/", "");
        webPath = webPath.replaceAll("[\\\\\\/]WEB-INF[\\\\\\/]classes[\\\\\\/]?", "/");
        webPath = webPath.replaceAll("[\\\\\\/]+", "/");
        webPath = webPath.replaceAll("%20", " ");

        if (webPath.matches("^[a-zA-Z]:.*?$")) {

        } else {
            webPath = "/" + webPath;
        }

        webPath += "/";
        webPath = webPath.replaceAll("[\\\\\\/]+", "/");

        return webPath;
    }
}
